package com.cxyzy.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.ToastUtils;

import org.json.JSONException;

import java.util.Map;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        parseJson();
    }

    private void parseJson() {
        try {
            String jsonStr = "{\"语文\":\"88\",\"数学\":\"78\",\"计算机\":\"99\"}";
            Map map = JsonUtil.jsonToMap(jsonStr);
            ToastUtils.showShort("语文成绩：" + map.get("语文").toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private void parseJsonByFastJson() {
        String jsonStr = "{\"语文\":\"88\",\"数学\":\"78\",\"计算机\":\"99\"}";
        Map map = (Map) JSON.parse(jsonStr);
        ToastUtils.showShort("语文成绩：" + map.get("语文").toString());
    }


}
